package com.kedacom.emptyproject.map.widget

import android.content.Context
import android.support.constraint.ConstraintLayout
import android.util.AttributeSet
import com.kedacom.emptyproject.MainApplication
import com.kedacom.emptyproject.R
import com.kedacom.emptyproject.util.dp2px

/**
 * 底部列表
 * @author GuanHaoran
 * @description:
 * @date :2020/10/16 3:40 PM
 */
class MyLayerBottomRecyView(context: Context, attributes: AttributeSet?, defStyle: Int = 0) :
    ConstraintLayout(context, attributes, defStyle) {

    constructor(ctx: Context, attributes: AttributeSet?) : this(
        context = ctx,
        attributes = attributes
    )

    constructor(ctx: Context) : this(context = ctx, attributes = null)

    private var MODE = 1

    init {
        val a = context.obtainStyledAttributes(
            attributes,
            R.styleable.BottomSheetBehavior_Layout
        )
//        MODE  =  a.getInt(R.styleable.BottomSheetBehavior_Layout_behavior_mode,-1)

//        margin(0,if (MODE == 1) 140 else 240,0,0)
    }

    override fun onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int) {
        super.onLayout(changed, left, top, right, bottom)
        MODE = MainApplication.UserLoginMode

        val a = (this.layoutParams as ConstraintLayout.LayoutParams).apply {
        }
        a.setMargins(0, if (MODE == 1) 140.dp2px() else 240.dp2px(), 0, 0)
        layoutParams = a


    }

    fun setPoi(midOffset: Float, float: Float) {
//        0.55873924-0
//        Log.e("qin","midOffset = $midOffset   float = $float")

        layoutParams = (this.layoutParams as ConstraintLayout.LayoutParams).apply {
            setMargins(
                0,
                if (MODE == 1) ((140 - 140 / midOffset * (midOffset - float)) + (20 - 20 / midOffset * float)).dp2px() else ((240 - 240 / midOffset * (midOffset - float)) + (20 - 20 / midOffset * float)).dp2px(),
                0,
                0
            )

        }

//        Log.e("qin","viewOffset = ${((240-240/midOffset*(midOffset -float)) +(20-20/midOffset*float))}")

    }
}